package chapter7;

import java.time.*;

public class NewDatePackageTest {
    public static void main(String[] args) {
        Clock clock = Clock.systemUTC();
        System.out.println("当前时刻为:" + clock.instant());
        System.out.println(clock.millis());
        System.out.println(System.currentTimeMillis());

        Duration d = Duration.ofSeconds(6000);
        System.out.println("6000秒相当于" + d.toMinutes() + "分");
        System.out.println("6000秒相当于" + d.toHours() + "小时");
        System.out.println("6000秒相当于" + d.toDays() + "天");

        Clock clock2 = clock.offset(clock, d);
        System.out.println("当前时间加6000秒为:" + clock2.instant());

        Instant instant = Instant.now();
        System.out.println(instant);
        Instant instant1 = instant.plusSeconds(6000);
        System.out.println(instant1);
        Instant instant2 = Instant.parse("2014-02-23T10:12:35.342Z");
        System.out.println(instant2);
        Instant instant3 = instant2.plus(Duration.ofHours(5).plusMinutes(4));
        System.out.println(instant3);
        Instant instant4 = instant3.minus(Duration.ofDays(5));
        System.out.println(instant4);

        LocalDate localDate = LocalDate.now();
        System.out.println(localDate);
        localDate = LocalDate.ofYearDay(2014, 146);
        System.out.println(localDate);
        localDate = LocalDate.of(2014, Month.MAY, 21);
        System.out.println(localDate);

        LocalTime localTime = LocalTime.of(22, 33);
        System.out.println(localTime);
        localTime = LocalTime.ofSecondOfDay(5503);
        System.out.println(localTime);

        LocalDateTime localDateTime = LocalDateTime.now();
        System.out.println(localDateTime);
        LocalDateTime future = localDateTime.plusHours(25).plusMinutes(3);
        System.out.println("当前日期的25小时3分后:" + future);


        Year year = Year.now();
        System.out.println("当前年份:" + year);
        year = year.plusYears(5);
        System.out.println("当前年份再过5年:" + year);

        YearMonth ym = year.atMonth(10);
        System.out.println("year年十月:" + ym);
        ym = ym.plusYears(5).minusMonths(3);
        System.out.println("year年十月再加5年减3个月:" + ym);

        MonthDay md = MonthDay.now();
        System.out.println("当前月日:" + md);
        MonthDay md2 = md.with(Month.MAY).withDayOfMonth(23);
        System.out.println("5月23日为:" + md2);
    }
}
